package io.renren.sf.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.sf.dao.HzCopyingSteleCalligraphyDao;
import io.renren.sf.entity.HzCopyingSteleCalligraphyEntity;
import io.renren.sf.service.HzCopyingSteleCalligraphyService;


@Service("hzCopyingSteleCalligraphyService")
public class HzCopyingSteleCalligraphyServiceImpl extends ServiceImpl<HzCopyingSteleCalligraphyDao, HzCopyingSteleCalligraphyEntity> implements HzCopyingSteleCalligraphyService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<HzCopyingSteleCalligraphyEntity> page = this.page(
                new Query<HzCopyingSteleCalligraphyEntity>().getPage(params),
                new QueryWrapper<HzCopyingSteleCalligraphyEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void updateAllRelatedSteleCalligraphyYears(Long oldId, String years, Long id) {
        this.baseMapper.updateAllRelatedSteleCalligraphyYears(oldId, years, id);
    }

    @Override
    public void updateAllRelatedSteleCalligraphyStyle(Long oldId, String style, Long id) {
        this.baseMapper.updateAllRelatedSteleCalligraphyStyle(oldId, style, id);
    }

    @Override
    public void updateAllRelatedSteleCalligraphyCalligrapher(Long oldId, String calligrapher, Long id) {
        this.baseMapper.updateAllRelatedSteleCalligraphyCalligrapher(oldId, calligrapher, id);
    }

    /**
     * 分页查找
     * @param curPage 当前页
     * @param pageSize 页大小
     * @return
     */
    @Override
    public List<HzCopyingSteleCalligraphyEntity> querySteleCalligraphy(Integer curPage, Integer pageSize, String years, String style, String calligrapher, String condition) {
        curPage = (curPage-1) * pageSize;
        return this.baseMapper.querySteleCalligraphy(curPage, pageSize, years, style, calligrapher, condition);
    }

    /**
     * 获取总记录数
     * @return
     */
    @Override
    public Integer querySteleCalligraphyNum(String years, String style, String calligrapher, String condition) {
        return this.baseMapper.querySteleCalligraphyNum(years, style, calligrapher, condition);
    }

    @Override
    public HzCopyingSteleCalligraphyEntity findOneById(Long id) {
        return this.baseMapper.selectOne(new QueryWrapper<HzCopyingSteleCalligraphyEntity>().eq("yid", id).or().eq("sid", id).or().eq("cid", id).last("limit 1"));
    }

    @Override
    public List<HzCopyingSteleCalligraphyEntity> findByIds(List<Long> sidList) {
        return this.baseMapper.selectList(new QueryWrapper<HzCopyingSteleCalligraphyEntity>().in("id",sidList));
    }

}